package com.lfg.message.delay.message.demo.delay.dl;

import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lfg
 * @version v1.0
 */
@RestController
public class Product1 {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/product/message")
    public String sendMessage() {
        rabbitTemplate.convertAndSend("dead-letter-exchange-name",
                "dead-letter-routing-key-name", "测试消息：Test message !", message -> {
                    //设定编码
                    message.getMessageProperties().setContentEncoding("utf-8");
                    //永久有效
                    message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);
                    //延时时间10s
                    message.getMessageProperties().setExpiration("10000");
                    return message;
                });
        return "已发送延时消息!";
    }
}
